package com.shinji.tratu;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DicRecentWordsAdapter extends BaseAdapter {
	private List<Word> listWords;
	Context context;

	public DicRecentWordsAdapter(Context context, List<Word> objects) {
		listWords = objects;
		this.context = context;
	}

	public void setListWords(List<Word> l) {
		this.listWords = l;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater infalInflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			v = infalInflater.inflate(R.layout.dic_recent_list_item, null);
		}
		final Word wordItem = (Word) getItem(position);
		if (wordItem != null) {
			TextView wordKey = (TextView) v.findViewById(R.id.key);
			wordKey.setText(wordItem.getKey());
			TextView wordDicType = (TextView) v.findViewById(R.id.dicType);
			wordDicType.setText(context.getResources().getStringArray(
					R.array.dic_array)[wordItem.getDicIndex()]);
		}
		return v;

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listWords.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return listWords.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

}
